package cn.edu.zafu.bigdata.liuwenyi;

abstract class Shape {
    //抽象方法，计算面积
    public abstract double area();
    //抽象方法，计算周长
    public abstract double perimeter();
    //final方法，不能被重写
    public final void display(){
        System.out.println("Shape Type:" + this.getClass().getSimpleName());
        System.out.println("Area: " + area());
        System.out.println("Perimeter: " + perimeter());
    }
}
class Circle extends Shape {
    private double radius;

    public Circle(double radius) {
        this.radius = radius;
    }

    @Override
    public double area() {
        return Math.PI * radius * radius;
    }

    @Override
    public double perimeter() {
        return 2 * Math.PI * radius;
    }
}

class Rectangle extends Shape {
    private double length;
    private double width;

    public Rectangle(double length, double width) {
        this.length = length;
        this.width = width;
    }

    @Override
    public double area() {
        return length * width;
    }

    @Override
    public double perimeter() {
        return 2 * (length + width);
    }
}
public class Shape_Test {
    public static void main(String[] args) {
        Shape circle = new Circle(5);
        Shape rectangle = new Rectangle(4, 6);

        circle.display();      // 调用 Circle 的 display 方法
        rectangle.display();   // 调用 Rectangle 的 display 方法
    }
}

